package com.xjj.order.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Service;

import lombok.extern.slf4j.Slf4j;

/**
 * @author zhanghejie
 * @date 2020/7/24 15:47
 */
//https://blog.csdn.net/las723/article/details/101207046
@Slf4j
@Service
public class TestService {

    @SentinelResource(value = "test1", blockHandler = "exceptionHandler")
    public String test1(String name) {
        return "Hello Nacos Discovery " + name;
    }

    @SentinelResource(value = "test2", fallback = "fallbackHandler")
    public String test2(String name) {
        return "Hello Nacos Discovery " + name;
        //throw new RuntimeException("发生异常");
    }

    // 限流与阻塞处理
    public void exceptionHandler(String str, BlockException ex) {
        log.error("blockHandler:" + str, ex);
    }

    // 熔断与降级处理
    public void fallbackHandler(String str) {
        log.error("fallbackHandler：" + str);
    }

}
